cmake_minimum_required(VERSION 3.6)
project(x264 VERSION 1.0.0 LANGUAGES C)
enable_language(ASM_NASM CXX C)
include_directories(include .)
set(CMAKE_C_FLAGS -std=c99)
set(SRCS common/osdep.c common/base.c common/cpu.c common/tables.c encoder/api.c)
set(SRCS_X common/mc.c common/predict.c common/pixel.c common/macroblock.c
        common/frame.c common/dct.c common/cabac.c
        common/common.c common/rectangle.c
        common/set.c common/quant.c common/deblock.c common/vlc.c
        common/mvpred.c common/bitstream.c
        encoder/analyse.c encoder/me.c encoder/ratecontrol.c
        encoder/set.c encoder/macroblock.c encoder/cabac.c
        encoder/cavlc.c encoder/encoder.c encoder/lookahead.c)

if (${CMAKE_ANDROID_ARCH_ABI} STREQUAL "armeabi-v7a")
    add_definitions(-D ARCH_ARM=1)
    set(SRCASM_X common/arm/bitstream-a.S
            common/arm/dct-a.S
            common/arm/deblock-a.S
            common/arm/mc-a.S
            common/arm/pixel-a.S
            common/arm/predict-a.S
            common/arm/quant-a.S)
    set(SRCS_X ${SRCS_X} common/arm/mc-c.c common/arm/predict-c.c)
elseif (${CMAKE_ANDROID_ARCH_ABI} STREQUAL "arm64-v8a")
    add_definitions(-D ARCH_AARCH64=1)
    set(SRCASM_X common/aarch64/bitstream-a.S
            common/aarch64/cabac-a.S
            common/aarch64/dct-a.S
            common/aarch64/deblock-a.S
            common/aarch64/mc-a.S
            common/aarch64/pixel-a.S
            common/aarch64/predict-a.S
            common/aarch64/quant-a.S)
    set(SRCS_X ${SRCS_X}
            common/aarch64/asm-offsets.c
            common/aarch64/mc-c.c
            common/aarch64/predict-c.c)
elseif (${CMAKE_ANDROID_ARCH_ABI} STREQUAL "x86")
    add_definitions(-D ARCH_X86=1)
    set(SRCASM_X
            common/x86/dct-32.asm
            common/x86/pixel-32.asm c
            ommon/x86/bitstream-a.asm
            common/x86/const-a.asm
            common/x86/cabac-a.asm
            common/x86/dct-a.asm
            common/x86/deblock-a.asm
            common/x86/mc-a.asm
            common/x86/mc-a2.asm
            common/x86/pixel-a.asm
            common/x86/predict-a.asm
            common/x86/quant-a.asm)
    set(SRCS_X ${SRCS_X} common/x86/mc-c.c common/x86/predict-c.c)
elseif (${CMAKE_ANDROID_ARCH_ABI} STREQUAL "x86_64")
    set(SRCASM_X
            common/x86/dct-32.asm
            common/x86/pixel-32.asm c
            ommon/x86/bitstream-a.asm
            common/x86/const-a.asm
            common/x86/cabac-a.asm
            common/x86/dct-a.asm
            common/x86/deblock-a.asm
            common/x86/mc-a.asm
            common/x86/mc-a2.asm
            common/x86/pixel-a.asm
            common/x86/predict-a.asm
            common/x86/quant-a.asm)
    set(SRCASM_X ${SRCASM_X} common/x86/dct-64.asm common/x86/trellis-64.asm)
    add_definitions(-D ARCH_X86_64=1)
endif ()
add_library(x264 SHARED  ${SRCASM_X}  ${SRCS} ${SRCS_X})
target_include_directories(x264 PUBLIC include)